USE Liberty
GO
-- ------------------------------------------------------------------------------------------------
-- ServiceMenEvents create table script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating ServiceMenEvents table...'
GO

IF OBJECT_ID( 'ServiceMenEvents' ) IS NULL
BEGIN
    CREATE TABLE dbo.ServiceMenEvents 
	(OID						bigint		IDENTITY(1, 1)	NOT NULL
	,Version					rowversion
	,ServiceMenID				bigint						NOT NULL
	,ActivityID					bigint						NOT NULL 
	,UserID						bigint						NOT NULL 
	,EventOccurred				datetime					NOT NULL
		CONSTRAINT DFLT_ServiceMenEvents_EventTime DEFAULT GETDATE()
	,EventNotes					varchar(MAX)					NULL

	,CONSTRAINT PK_ServiceMenEvents PRIMARY KEY CLUSTERED (OID)

	,CONSTRAINT FK_ServiceMenEvents_ServiceMen FOREIGN KEY (ServiceMenID)
		REFERENCES DBO.ServiceMen(OID)

	,CONSTRAINT FK_ServiceMenEvents_TypeOfActivity FOREIGN KEY (ActivityID) 
		REFERENCES DBO.TypesOfActivity(OID)

	,CONSTRAINT FK_ServiceMenEvents_Users FOREIGN KEY (UserID)
		REFERENCES DBO.Users(OID)

	)
	PRINT 'ServiceMenEvents table has been created...'
END
ELSE
BEGIN
	PRINT 'ServiceMenEvents table already exists'
END
GO

